import java.util.*;

public class LoopAssignments {
	public static void main(String[] args) {
		// 1
		System.out
				.println("Expected:\n1, 2, 3, 4, 5,\n6, 7, 8, 9, 10,\n11, 12, 13, 14, 15,\n16, 17");
		System.out.println();
		System.out.println();
		print1toN(17);
		System.out.println();
		// 2
		System.out.println("Expected 153");
		System.out.println(sumN(17));
		System.out.println();
		// 3
		System.out.println("Expected -1");
		System.out.println(sumStartToEnd(10, 14));
		System.out.println();
		// 4
		System.out.println("Expected");
		System.out.println("Hello");
		System.out.println("Hello");
		System.out.println("Hello");
		System.out.println("Hello");
		System.out.println("Hello");
		System.out.println("Real");
		repeatWord("Hello");
		System.out.println();
		// 5
		System.out.println("Expected");
		System.out.println("loop.............153\niteration......isFun");
		System.out.println("real");
		indexBook("loop", "153");
		indexBook("iteration", "isFun");
		System.out.println();
		// 6
		System.out.println("Expected 24");
		System.out.println(factorial(4));
		System.out.println("Expected 5040");
		System.out.println(factorial(7));
		System.out.println();
		// 7
		System.out.println("Expected " + Math.pow(5, 7));
		System.out.println(integerPower(5d, 7));
		System.out.println();
		// 8
		System.out.println("Expected 2.147483647E9");
		System.out.println(integerPower(5, 23));
		System.out.println();
		// 9
		System.out
				.println("Expected:\nHow many integers will be added: 5\nEnter an integer: 3\nEnter an integer: 4\nEnter an integer: -4\nEnter an integer: -3\nEnter an integer: 7\nThe sum is 7\nThe min is -4\nThe max is 7\nThe range is 11\nThe average is 1.4");
		System.out.println();
		// 10
		System.out.println("Expected");
		System.out.println("*******");
		System.out.println("******");
		System.out.println("*****");
		System.out.println("****");
		System.out.println("***");
		System.out.println("**");
		System.out.println("*");
		System.out.println("Real");
		System.out.println();
		printStarWedge(7);
		System.out.println();

	}

	/**
	 * Number 1
	 * 
	 * @param n
	 */
	public static void print1toN(int n) {
		for (int i = 1; i <= n; i++) {
			System.out.print(i + (i != n ? ", " : "")
					+ (i % 5 == 0 ? "\n" : ""));
		}
	}

	/**
	 * Number 2
	 * 
	 * @param n
	 * @return
	 */
	public static int sumN(int n) {
		if (0 > n)
			return -1;
		int c = 0;
		for (int i = 0; i <= n; i++) {
			c += i;
		}
		return c;
	}

	/**
	 * Number 3
	 * 
	 * @param start
	 * @param end
	 * @return
	 */
	public static int sumStartToEnd(int start, int end) {
		if (end < start)
			return -1;
		int c = 0;
		for (int i = start; i <= end; i++) {
			c += i;
		}
		return c;
	}

	/**
	 * Number 4
	 * 
	 * @param word
	 */
	public static void repeatWord(String word) {
		for (int i = 0; i < word.length(); i++) {
			System.out.println(word);
		}
	}

	/**
	 * Number 5
	 * 
	 * @param a
	 * @param b
	 */
	public static void indexBook(String a, String b) {
		System.out.print(a);
		for (int i = 0; i < 20 - (a.length() + b.length()); i++) {
			System.out.print(".");
		}
		System.out.print(b);
		System.out.println();
	}

	/**
	 * Number 6
	 * 
	 * @param base
	 * @param exponent
	 * @return
	 */
	public static double factorial(int n) {
		int r = 1;
		for (int i = n; i > 0; i--) {
			r = r * i;
		}
		return r;
	}

	/**
	 * Number 7
	 * 
	 * @param base
	 * @param exponent
	 * @return
	 */
	public static double integerPower(double base, int exponent) {
		int n = 1;
		for (int i = 0; i < exponent; i++) {
			n *= base;
		}
		return n;
	}

	/**
	 * Number 8
	 * 
	 * @param n
	 * @return
	 */
	public static double sumReciprocal(int n) {
		if (0 > n)
			return -1;
		double c = 0;
		for (int i = 0; i <= n; i++) {
			c += 1d / i;
		}
		return c;
	}

	public static void doStuff() {
		Scanner s = new Scanner(System.in);
		System.out.print("How many integers will be added: ");
		int n = s.nextInt();
		computeNumbers(n);

	}

	public static void computeNumbers(int n) {
		Scanner s = new Scanner(System.in);
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		int sum = 0;
		for (int i = 0; i <= n; i++) {
			System.out.println("Enter an integer: ");
			int r = s.nextInt();
			if (r > max)
				max = r;
			if (r < min)
				min = r;
		}
		System.out.println();
		System.out.println("The sum is " + sum);
		System.out.println("The max is " + max);
		System.out.println("The min is " + min);
		System.out.println("The average is " + sum / n);
		System.out.println("The range is " + (max - min));
	}

	public static void printStarWedge(int n) {
		for (int i = n; i >= 0; i--) {
			System.out.println();
			for (int b = 0; b < i; b++) {
				System.out.print("*");
			}
		}
	}
}
